<?php
include '../../init.php';

include DIR_CORE.'mysql.php';

//var_dump($_POST);

//接受数据
$type_name = $_POST['type_name'];

//判断类型是否存在
$sql="select * from type where type_name= '$type_name'";
$res = mysqli_query($link, $sql);
if (mysqli_num_rows($link, $res) > 0) {
    echo '类型已存在！';
} else {
    //数据入库
    $sql = "insert into type values(null,'$type_name')";
    $result = mysqli_query($link, $sql);

    if ($result) {
        echo '<span style="color:green;font-weight:bold;">添加成功</span>';
    } else {
        echo '<span style="color:red;font-weight:bold;">添加失败</span>';
    }
}
